var nc:NetConnection;

function getInstance()
{
	if (nc==null)
	{
		init();
	}

	return nc;
}

function init()
{
	nc=new NetConnection();
	nc.owner=this;
	nc.connected=false;
	nc.onStatus=function(infoObj)
	{
		 Packages.log("Status(NetConnection)", "debug");
		 Packages.log("Level: "+infoObj.level, "debug");
		 Packages.log("Code: "+infoObj.code, "debug");
		
		if (infoObj.code=="NetConnection.Connect.Success")
		{
			
			this.connected=true;

			Packages.log("NetConnection.Connect.Success...", "info");
			Packages.system.mlf.GateKeeper.dispatchMessage({type:"onRTMPConnected"});
		}
		else if (infoObj.code=="NetConnection.Connect.Closed" || infoObj.code=="NetConnection.Connect.Failed")
		{
			this.connected=false;
			this.owner.init();
		}
	}
	
	nc.connect(Packages.system.mlf.GateKeeper.accessSystemConfig("rtmpURI"));
}

function close()
{
	nc.connected=false;
	nc.close();
	delete nc;
}